<?php
class Menu
{
	/**
	 * Store menu items
	 * @var array
	 */
	public $items;
	/**
	 * Store current active menu item
	 * @var array
	 */
	public $activeItem;
	/**
	 * store current page request
	 * @var unknown_type
	 */
	public $uri;
	/**
	 * Class constructor
	 * @param $request
	 * @param $items
	 */
	function __construct($uri, $items = array ())
	{
		$this->items = $items;
		$this->uri = $uri;
		$this->activateItem();
	}
	/**
	 * Method for find current active item
	 */
	function activateItem()
	{
		if(! is_array($this->items))
			return false;
		if(! sizeof($this->items))
			return false;
		
		foreach($this->items as $id => &$item)
		{
			$url = parse_url($item->url);
			$root_url = parse_url($this->uri);
			
			if(! isset($url ["path"]))
				continue;
			
			if($url ["path"] == $root_url ["path"])
			{
				$item->activate();
				
				$this->activeItem = $item;
				
			} elseif(strlen(trim($url ["path"], "/")))
			{
				// Check for url mistmatch
				if(strstr($root_url ["path"], $url ["path"]))
				{
					// Activate menu
					$item->activate();
					
					$this->activeItem = $item;
				}
			}
		}
	}
	public function getSubmenu()
	{
		return $this->activeItem->menu;
	}
	
	/**
	 * Get current menu items
	 */
	function getItems()
	{
		return $this->items;
	}
	
	/**
	 * Method to construct html
	 */
	function render()
	{
	
	}
}

?>